/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @ChildPostAdapter.java  2014年9月11日 下午3:45:34 - Jerry
 * @author JiangYue
 * @version 1.0
 */

package com.android.tiango.baba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.android.scsd.tiango.R;
import com.android.tiango.baba.act.ActCardDetail;
import com.android.tiango.baba.entity.SimpleTopicModel;
import com.android.tiango.baba.util.Constants;
import com.android.tiango.baba.util.TimeToUtil;
/**
 * 我的帖子-我的发帖-子帖子
 * @author txg
 *
 */
public class ChildPostAdapter extends BaseAdapter implements ListAdapter {
	private ArrayList<SimpleTopicModel> mDate;
	private Context context;

	public ChildPostAdapter(ArrayList<SimpleTopicModel> mDate,Context context) {
		this.mDate = mDate;
		this.context = context;
	}

	@Override
	public int getCount() {
		return mDate.size();
	}

	@Override
	public SimpleTopicModel getItem(int position) {
		return mDate.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ItemTag tag;
		if (convertView == null) {
			tag = new ItemTag();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_myposts_child, null);
			tag.tv_acttnote = (TextView) convertView.findViewById(R.id.tv_acttnote);
			tag.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
			tag.tv_actcomments = (TextView) convertView.findViewById(R.id.tv_actcomments);
			tag.tv_acttoview = (TextView) convertView.findViewById(R.id.tv_acttoview);
			convertView.setTag(tag);
		} else {
			tag = (ItemTag) convertView.getTag();
		}
		final SimpleTopicModel simpleTopicModel = getItem(position);
		if(simpleTopicModel != null ) { 
		tag.tv_acttnote.setText(simpleTopicModel.getTopicName()); 
		 
		tag.tv_time.setText(TimeToUtil.getSystemTimeSetFormat(simpleTopicModel.getCreateTime(), TimeToUtil.ACCURATE_TO_THE_DAY));
		tag.tv_actcomments.setText(simpleTopicModel.getReadNumber()+"");
		tag.tv_acttoview.setText(simpleTopicModel.getReplyNumber()+"");
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, ActCardDetail.class);
				intent.putExtra(Constants.BARID, simpleTopicModel.getBarId());
				intent.putExtra(Constants.TOPICID, simpleTopicModel.getTopicId());
				intent.putExtra(Constants.BARNAME, simpleTopicModel.getBarName());
				context.startActivity(intent);
			}
		});
		}
		return convertView;
	}

	class ItemTag {
		TextView tv_acttnote; 
		TextView tv_time;
		TextView tv_actcomments;
		TextView tv_acttoview;
	}
}
